// pages/personal/team/team.js
const app = getApp();
Page({

    /**
     * 页面的初始数据
     */
    data: {
        page: 1,
        total: 2,
        list: [],
        loading: false,
        status: 1,
        payPage: 1,
        payTotal: 2,
        payList: [],
        payLoading: false,
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        this.loadData();
    },
    loadData() {
        if (this.data.page > this.data.total || this.data.loading) {
            return;
        }
        this.setData({ loading: true })
        app.http.get('member/my-fans', {
            data: {
                page: this.data.page
            }
        }).then(res => {
            this.setData({
                page: this.data.page + 1,
                total: res.data.total,
                list: this.data.list.concat(res.data.items),
                loading: false
            })
        }).catch(err => {
            app.wxToast.error(err.message);
        })
    },
    loadPayMember() {
        if (this.data.payPage > this.data.payTotal || this.data.payLoading) {
            return;
        }
        this.setData({ payLoading: true })
        app.http.get('member/vip-fans', {
            data: {
                page: this.data.payPage
            }
        }).then(res => {
            if (res.data != null) {
                this.setData({
                    payPage: this.data.payPage + 1,
                    payTotal: res.data.payTotal,
                    payList: this.data.payList.concat(res.data.items),
                })
            }
            this.setData({ payLoading: false })
        }).catch(err => {
            app.wxToast.error(err.message);
        })
    },
    setStatus(e) {
        this.setData({
            status: e.currentTarget.dataset.status
        })
        if (this.data.status == 2) {
            this.setData({
                payPage: 1,
                payTotal: 2,
                payList: [],
                payLoading: false,
            })
            this.loadPayMember();
        }
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {
        if (this.data.status == 1) {
            this.setData({
                page: 1,
                total: 2,
                list: [],
                loading: false,
            })
            this.loadData();
        } else if (this.data.status == 2) {
            this.setData({
                payPage: 1,
                payTotal: 2,
                payList: [],
                payLoading: false,
            })
            this.loadPayMember();
        }
    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {
        if (this.data.status == 1) {
            this.loadData();
        } else if (this.data.status == 2) {
            this.loadPayMember();
        }
    },

    
})